package org.kfive.nova.desginpattern.builder;

/*
 * Copyright (c) 2016 lizhanwu.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * <p>
 * Product.java
 *
 * Application:
 * NO
 *
 * Limited:
 * NO
 *
 * Warning:
 * NO
 *-----------------------------------------------------------------------------
 *         VERSION       DATE            BY       CHANGE/COMMENT
 * -----------------------------------------------------------------------------
 *          1.0      2016-12-216:11     lizhanwu      create
 * -----------------------------------------------------------------------------
 * </p>
 */
public class Product {

    private Integer id;

    private String name;

    private String unit;

    private Double price;

    public Product(Integer id,String name,String unit,Double price){
        this.id = id;
        this.name = name;
        this.unit = unit;
        this.price = price;
    }

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getUnit() {
        return unit;
    }

    public Double getPrice() {
        return price;
    }

    public static class Builder{
        private Integer id;

        private String name;

        private String unit;

        private Double price;

        public Builder setId(Integer id) {
            this.id = id;
            return this;
        }

        public Builder setName(String name) {
            this.name = name;
            return this;
        }

        public Builder setUnit(String unit) {
            this.unit = unit;
            return this;
        }

        public Builder setPrice(Double price) {
            this.price = price;
            return this;
        }

        public static Builder newBuilder(){
            return new Builder();
        }

        public Product build(){
            return new Product(this.id,this.name,this.unit,this.price);
        }
    }

    public static void main(String[] args) {
        Product.Builder builder = Product.Builder.newBuilder();
        Product product = builder.setId(1).setName("测试").setUnit("包").setPrice(100D).build();
    }
}
